
<div class="ypfood-head">
    <div class="back-div" onClick="javascript :history.back(-1);"><img src="/statics/imgs/head-back.png"></div>
    <div >
        <span class="title-span">微信支付</span>
    </div>
</div>

<div id="weixinPay">
    <div class="title">
        微信支付
    </div>
    <div style="margin: 10px 0;width: 100%;text-align: center;">
        订单编号：<span id="sn-span" style="word-break: break-all">${param.sn}</span>
    </div>
    <div class="repay" onclick="callpay()">
        重新支付
    </div>
</div>
<script>
    //调用微信JS api 支付
    function jsApiCall() {
        WeixinJSBridge.invoke(
                'getBrandWCPayRequest',
                ${param.p},
                function (res) {
                    //支付成功或失败前台判断
                    if (res.err_msg == 'get_brand_wcpay_request:ok') {
                        var sn=$("#sn-span").html();
                            window.location.href = "/order/payok.jspa?orderSn="+${param.sn};
                    } else {
                        alert('支付失败');
                    }
                });
    }

    function callpay() {
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        } else {
            jsApiCall();
        }
    }

    window.onload = function () {
        callpay();
    };
</script>